package com.projectnection.server.webservices;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.projectnection.server.database.entities.ConnectEntity;
import com.projectnection.server.database.entities.GetEntity;
import com.projectnection.server.model.Entity;

@SuppressWarnings("serial")
public class ConnectEntityServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException {

		String entityIDFrom = request.getParameter("entityIDFrom");

		String entityIDTo = request.getParameter("entityIDTo");

		Entity entityFrom = GetEntity.get(entityIDFrom);

		ConnectEntity.save(entityFrom, entityIDTo);

		String answer = Utilities.getCallbackResponse(request
				.getParameter("callback"));

		response.setContentType("text/javascript");

		response.getWriter().println(answer);
	}
}
